import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-07-22
 * Time: 14:39
 */
public class Test {
    public static void main(String[] args) {
        CardDemo cardDemo = new CardDemo();
        ////买一副牌
        List<Card> cardList = cardDemo.buyCard();
        System.out.println("购买牌："+cardList);
        //洗牌
        cardDemo.shuffle(cardList);
        System.out.println("洗牌后："+cardList);
        //3个人，每人轮流摸5张，每轮一人一张，一共5张
        List<List<Card>> list = cardDemo.play(cardList);
        for (int i = 0; i < list.size(); i++) {
            System.out.println("第" + (i+1)+ "人的牌" + list.get(i));
        }
        System.out.println("剩下的牌: " + cardList);
    }
    public List<List<Integer>> generate (int numRows) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        list.add(list0);
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            //首
            curRow.add(1);
            //中间
            List<Integer> preRow = new ArrayList<>(list.get(i-1));
            for (int j = 1; j < i; j++) {
                Integer val1 = preRow.get(j-1);
                Integer val2 = preRow.get(j);
                curRow.add(val1+val2);
            }
            //尾
            curRow.add(1);
            list.add(curRow);
        }
        return list;
    }

    public static void main4(String[] args) {
        String str1 = "hello bit world";
        String str2 = "eloi";
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0; i < str1.length();i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch + "") ) {
                list.add(ch);
            }
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i));
        }
    }
    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println(list);

        System.out.println("====使用for循环====");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("====使用for each====");
        for (Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();

        System.out.println("=====使用Iterator迭代器====");
        Iterator<Integer> iterator = list.iterator();
        while(iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

        System.out.println("=====使用ListIterator迭代器====");
        ListIterator<Integer> iterator1 = list.listIterator();
        while (iterator1.hasNext()) {
            System.out.print(iterator1.next() + " ");
        }
        System.out.println();

        System.out.println("=====使用Iterator迭代器 逆序====");
        ListIterator<Integer> iterator2 = list.listIterator(list.size());
        while(iterator2.hasPrevious()) {
            System.out.print(iterator2.previous() + " ");
        }

    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(1,99);
        System.out.println(list);
        ArrayList<Integer> list1 = new ArrayList<>();
        list1.addAll(list);
        System.out.println(list1);

        list1.remove(1);
        list.remove(new Integer(99));
        System.out.println(list);
        System.out.println(list1);

        Integer ret = list.get(1);
        System.out.println(ret);
        list.set(1,100);
        System.out.println(list);

        if(list.contains(100)) {
            System.out.println("有100");
        }else {
            System.out.println("没有100");
        }

        Integer retIndex = list.indexOf(1);
        System.out.println(retIndex);
        list.add(1);//[1, 100, 3, 1]
        Integer retLastIndex = list.lastIndexOf(1);
        System.out.println(retLastIndex);

        List<Integer> list2 = list.subList(2,4);
        System.out.println(list2);
        list2.set(0,100);
        System.out.println(list2);
        System.out.println(list);

    }
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println(list);

        ArrayList<Integer> list1 = new ArrayList<>(12);
        list1.add(11);
        list1.add(21);
        list1.add(31);
        System.out.println(list1);

        ArrayList<Integer> list2 = new ArrayList<>(list);
        System.out.println(list2);

        List<Integer> list3 = new ArrayList<Integer>();
        list3.add(10);
        list3.add(9);
        list3.add(8);
        System.out.println(list3);
        List<Integer> list4 = new ArrayList<>(12);

    }
}
